<?php
require_once('includes/common.php');

if(strpos($_SERVER['HTTP_REFERER'],'register.php') === false){
  header('location:register.php');
}

if($_FILES['avatar']['error'] != 0 ||
$_FILES['avatar']['size'] > 2*1024*1024
){
  // redirect
}
$fileName = date('Ymdhis').'_'.$_FILES['avatar']['name'];
$source = $_FILES['avatar']['tmp_name'];
$dest = "uploads/$fileName";
//copy($source,$dest);
move_uploaded_file($source,$dest);
//////////////// Manipulate Data Before Insert///
$_POST['lang'] = implode(',',$_POST['lang']);
$_POST['hobbies'] = implode(',',$_POST['hobbies']);
$_POST['password'] = md5($_POST['password']);
$_POST['avatar'] = $fileName;
$_POST['added_date'] = date('Y-m-d H:i:s');
unset($_POST['conPassword']);
/////////////////////////////////////////////////
//vx($_POST);
//pr($_FILES);
/////////Save USer Here/////////
 insert('users',$_POST);
/////////////////////////////
$_SESSION['msg'] = '<span class="success">Registration Completed Successfilly.Please Login to Continue.</span>';
header('Location:index.php');
